import java.util.Random;

public class MathExerciseGenerator {
    public static void main(String[] args) {
        generateExercises(50);
    }

    public static void generateExercises(int count) {
        Random random = new Random();
        System.out.println("===== 100以内加减法习题集 =====\n");

        for (int i = 1; i <= count; i++) {
            // 随机生成两个100以内的数字
            int num1 = random.nextInt(100);
            int num2 = random.nextInt(100);
            
            // 随机决定是加法还是减法
            boolean isAddition = random.nextBoolean();
            
            if (isAddition) {
                // 加法：确保结果不超过100
                System.out.printf("%2d. %2d + %2d = ", i, num1, num2);
            } else {
                // 减法：确保被减数大于或等于减数，避免出现负数结果
                if (num1 < num2) {
                    int temp = num1;
                    num1 = num2;
                    num2 = temp;
                }
                System.out.printf("%2d. %2d - %2d = ", i, num1, num2);
            }
            
            // 每5道题换一行
            if (i % 5 == 0) {
                System.out.println();
            }
        }
        
        System.out.println("\n===== 习题结束 =====");
    }
}